by Gene Olafsen
In This Chapter
There are essentially two types of OLE server objects: automation servers and document servers. Likewise, the document server category can be further divided into in-place servers and active document servers. In-place editing server applications are those OLE server applications that MFC has supported for a number of releases and are compatible with the container applications that AppWizard creates. There are a few differences between in-place servers and active documents, which I will explore later in this chapter.
Active documents, from a framework perspective, use classes that derive from the in-place object server classes. This derivation offers a set of classes that tailor the more general OLE server base classes into a new breed of base classes for active document support. Specifically, this change involves using a new in-place frame class and a different server item class.
Document servers are applications that you probably use every day. Both Microsoft Word and Excel are perfect examples of OLE document servers. In Figure 12.1, an Excel spreadsheet is shown in-place active in a Word document. You can see how convenient it is to edit a documents data using the application in which it was created.
Figure 12.1 Excel in-place active inside Word.
You have a number of options when using AppWizard to create your document server application, as shown in Figure 12.2.
Figure 12.2 AppWizard document server options (step 3).
A full server is the real deal. You can execute a full server either as a standalone application or from within a container. Because the server can act as a standalone application, it can load, store, and create data files. A container application can then either instantiate full server objects to create embedded data items, or activate the server by linking to external data files.
An active document server derives from OLE server technology. From an MFC coding view, there is little that differentiates an active document from a more traditional OLE server object other than a couple of classes and the addition of some command message routing.
The differences between active documents and OLE server objects are purported to be advantages. The following is a list of differences (read advantages) of active documents over embedding servers:
AppWizard offers options to implement any server as an active document server and any container as an active document container.
A container-server application is one that can function either as a standalone container program, in which case you can link or embed other document servers, or embedded as a document server in a different container. In fact, your server can continue to act as a container while it is performing server functions for a container. It sounds a bit more complex than it really is. Both Microsoft Excel and Word are container-server applications. As container applications, either can embed the other performing in its document server role. In the most extreme scenario, a document server retains its container functionality; thus, it can offer document viewing and activation facilities.
A mini-server offers a subset of full server functionality. The most differentiating aspect of a mini-server is that it cannot run as a standalone application. Because the server can never execute in the same sense as a normal application, it can load only as store data through the container application. Mini-servers can only be embedded in a server, as linking requires the document data to exist outside the containers documentsomething that you have already seen is not permitted.
When creating a document server, there is no better place to start than with AppWizard (see Figure 12.3). The project name for the application is activedocserv. You will see how to create a simple active document server and then host it in Internet Explorer.
Figure 12.3 Starting the activedocserv project.
The concept of OLE Documents can be found in the initial release of OLE. After all, the words Object Linking and Embedding describe a document-centric technology. The early implementation of OLE documents was very crude, generally requiring an object packager utility to combine the elements of the document. Today, OLE document construction occurs seamlessly in word processors and spreadsheets, while viewing such documents can even occur in Web browsers.
Servers and the Document/View Architecture
MFCs implementation of embedding servers leverages the document/view architecture to manage multiple container support. Servers are very complicated animals, requiring operation under a number of circumstances. One of the most taxing of all situations is a document server object simultaneously supporting two containers. Your server will handle this situation differently depending on the options that you select in AppWizard when constructing the server application, as shown in Figure 12.4. An OLE server that is an MDI application simply opens a new window for each document that the server requires to support. Hence, a single instance of the executable can handle multiple container requests or multiple document instantiations in a single container. An SDI server or mini-server doesnt contain the necessary framework wiring for a single application instance to share across multiple containers. The solution to this problem is multiple application instances.
Figure 12.4 Document architecture selection.
The activedocserv application will only be an SDI application. As part of navigating through the wizard, you should also do the following: